package com.gua.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import io.swagger.annotations.ApiOperation;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

/**
 * https://blog.csdn.net/weixin_42078172/article/details/120818038
 * https://zhuanlan.zhihu.com/p/593937567
 * 
 * @author huangjj
 *
 */
@Configuration
public class Swagger3Config {
	
	 // 控制是否允许swagger
	@Value("${swagger.enable:true}")
    private boolean enableSwagger;
	
	@Bean
	public Docket createRestApi() {
		return new Docket(DocumentationType.OAS_30)
				.enable(enableSwagger) //是否启动swagger配置
				.apiInfo(apiInfo()).select()
				.apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
				.paths(PathSelectors.any())
				.build();
	}

	private ApiInfo apiInfo() {
		return new ApiInfoBuilder().title("接口文档")
				.description("http://localhost:8099/swagger-ui/index.html").version("1.0")
				.build();
	}
}
